var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), e = require("../../../@babel/runtime/helpers/asyncToGenerator"), a = require("../../../@babel/runtime/helpers/defineProperty"), n = require("../common.js"), r = getApp();

Page({
    behaviors: [ n ],
    data: {
        collapseActive1: [],
        collapseActive2: [],
        collapseActive3: [],
        treeData: [],
        maxLevel: 1,
        page: 1,
        loading: !1,
        finished: !1
    },
    onLoad: function(t) {
        this.getData();
    },
    initData: function() {
        this.data.page = 1, this.data.loading = !1, this.setData({
            finished: !1
        });
    },
    onReady: function() {},
    onShow: function() {},
    getData: function() {
        var t = this;
        if (this.data.loading || this.data.finished) return !1;
        this.data.loading = !0;
        var e = r.getNetAddresss("plugin.shop-assistant.frontend.category.get-list");
        r._postNetWork({
            url: e,
            data: {
                page: this.data.page
            },
            success: function(e) {
                t.data.loading = !1;
                var a = e.data;
                if (1 != a.result) return r.tips(a.msg);
                var n = {};
                n.maxLevel = a.data.setLevel;
                var i = a.data.list;
                (i.current_page >= i.last_page || i.data.length < i.per_page) && (n.finished = !0), 
                t.data.page++, n.treeData = i.current_page > 1 ? t.data.treeData.concat(i.data) : i.data, 
                t.setData(n);
            }
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    collapseActiveChange: function(t) {
        var e = t.currentTarget.dataset.name;
        this.setData(a({}, e, t.detail));
    },
    handOperation: function(t) {
        var e = this, a = t.detail.name, n = t.detail.level, r = [ "添加子类", "编辑", "删除" ];
        (3 == n || 2 == n && 2 == this.data.maxLevel) && r.shift(), wx.showActionSheet({
            itemList: r,
            success: function(t) {
                var r = t.tapIndex;
                3 == n || 2 == n && 2 == e.data.maxLevel ? 1 == r ? e.deleteCategory(a) : 0 == r && e.toDditCategory(a) : 0 == r ? e.toAddCategory(a) : 1 == r ? e.toDditCategory(a) : 2 == r && e.deleteCategory(a);
            },
            fail: function(t) {}
        });
    },
    toAddCategory: function(t) {
        wx.navigateTo({
            url: "/packageF/storeManagement/editGoodsCatgory/editGoodsCatgory?parentId=" + t
        });
    },
    toDditCategory: function(t) {
        wx.navigateTo({
            url: "/packageF/storeManagement/editGoodsCatgory/editGoodsCatgory?categoryId=" + t
        });
    },
    deleteCategory: function(a) {
        var n = this;
        return e(t.default.mark(function e() {
            var i;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return t.next = 2, r.confirm("正在删除改分类，请确认操作");

                  case 2:
                    if (t.sent) {
                        t.next = 5;
                        break;
                    }
                    return t.abrupt("return");

                  case 5:
                    i = r.getNetAddresss("plugin.shop-assistant.frontend.category.delete"), r._postNetWork({
                        url: i,
                        data: {
                            id: a
                        },
                        success: function(t) {
                            var e = t.data;
                            if (1 != e.result) return r.tips(e.msg);
                            n.initData(), n.getData();
                        }
                    });

                  case 7:
                  case "end":
                    return t.stop();
                }
            }, e);
        }))();
    },
    onShareAppMessage: function() {}
});